	@include("user.head")
	<!-- 公共头部 -->
	<div id="content_person">
	<div class="row">
		<div class="col-xs-3">
			@include("user.uc.navigation")
		</div>
		<div class="col-xs-9">
			<div class="panel panel-default">
			    <div class="panel-heading">
		   	 		<h3 class="panel-title">项目编辑</h3>
		  		</div>
				<div class="panel-body">
					<div class="form-horizontal">
					    <div class="form-group">
					      <label class="col-xs-3 control-label no_padding_right">项目名称:</label>
					      <div class="col-xs-6">
					        <input class="form-control input_size" name="name" placeholder="" type="text">
					      </div>
					    </div>

					    <div class="form-group">
					      <label class="col-xs-3 control-label no_padding_right">投资规模(万元):</label>
					      <div class="col-xs-6">
					        <input class="form-control input_size" name="investment_scale" placeholder="" type="text">
					      </div>
					    </div>

					    <div class="form-group">
					      <label class="col-xs-3 control-label no_padding_right">投资模式:</label>
					      <div class="col-xs-6">
					        <select class="form-control input_size" name="investment_type_id">
					          <option value="">请选择</option>
					        </select>
					      </div>
					    </div>

					    <div class="form-group">
					      <label class="col-xs-3 control-label no_padding_right">节能效率:</label>
					      <div class="col-xs-6">
					        <input class="form-control input_size" name="efficiency" autocomplete="of" placeholder="" type="text">
					      </div>
					    </div>

					    <div class="form-group">
					      <label class="col-xs-3 control-label no_padding_right">项目启动时间:</label>
					      <div class="col-xs-6">
					        <input class="form-control input_size date-time-picker" readonly name="start_time" autocomplete="of" placeholder="" type="text">
					      </div>
					    </div>

					    <div class="form-group">
					      <label class="col-xs-3 control-label no_padding_right">项目结束时间:</label>
					      <div class="col-xs-6">
					        <input class="form-control input_size date-time-picker" readonly name="end_time" autocomplete="of" placeholder="" type="text">
					      </div>
					    </div>

					    <div class="form-group">
					      <label class="col-xs-3 control-label no_padding_right">省:</label>
					      <div class="col-xs-6">
					      	<select class="form-control fl" name="province" style="float: left; width:300px;" id="province">
					      	  <option value="-1">请选择</option>
					      	</select>
					      </div>
					    </div>

					    <div class="form-group">
					      <label class="col-xs-3 control-label no_padding_right">市:</label>
					      <div class="col-xs-6">
					      	<select class="form-control fl" name="city" style="float: left; width:300px;" id="city">
					      	  <option value="-1">请选择</option>
					      	</select>
					      </div>
					    </div>

					    <div class="form-group">
					      <label class="col-xs-3 control-label no_padding_right">区:</label>
					      <div class="col-xs-6">
					      	<select class="form-control fl" name="area" style="float: left; width:300px;" id="area">
					      	  <option value="-1">请选择</option>
					      	</select>
					      </div>
					    </div>

						<div class="form-group">
						  <label class="col-xs-3 control-label no_padding_right">详细地址:</label>
						  <div class="col-xs-6">
						    <input class="form-control input_size" name="address" autocomplete="of" placeholder="" type="text">
						  </div>
						</div>

					    <div class="form-group">
					      <label class="col-xs-3 control-label no_padding_right">是否申请奖励:</label>
					      <div class="col-xs-6">
					        <div class="radio">
					          <label>
					            <input name="is_request_award" id="" value="0" checked="" type="radio">
					            否
					          </label>
					          <label>
					            <input name="is_request_award" id="" value="1" type="radio">
					            是
					          </label>
					        </div>
					      </div>
					    </div>

					    <div class="form-group">
					      <label class="col-xs-3 control-label no_padding_right">是否申请补贴:</label>
					      <div class="col-xs-6">
					        <div class="radio">
					          <label>
					            <input name="is_request_subsidy" id="" value="0" checked="" type="radio">
					            否
					          </label>
					          <label>
					            <input name="is_request_subsidy" id="" value="1" type="radio">
					            是
					          </label>
					        </div>
					      </div>
					    </div>

					    <div class="form-group">
					      <label class="col-xs-3 control-label no_padding_right">是否申请退税:</label>
					      <div class="col-xs-6">
					        <div class="radio">
					          <label>
					            <input name="is_request_rebate" id="" value="0" checked="" type="radio">
					            否
					          </label>
					          <label>
					            <input name="is_request_rebate" id="" value="1" type="radio">
					            是
					          </label>
					        </div>
					      </div>
					    </div>

					    <div class="form-group">
					      <label class="col-xs-3 control-label no_padding_right">项目图片:</label>
					      <div class="col-xs-6">
					        <a href="javascript:;" class="file btn btn-primary">上传
					            <input type="file" name="imgFile" id="projectImg">
					            <input type="hidden" class="hiddenName" name="image">
					        </a><span class="fileName"></span>
					      </div>
					    </div>

					    <div class="form-group">
					      <label class="col-xs-3 control-label no_padding_right">应用主体:</label>
					      <div class="col-xs-6">
					        <select class="form-control input_size" name="mb_id" id="mbList">
					        	<option value="">请选择</option>
					        </select>
					      </div>
					    </div>


					    <div class="form-group domainGroup">
					      <label class="col-xs-3 control-label no_padding_right">应用领域:</label>
					      <div class="col-xs-3">
					        <select class="form-control input_size app_domain">
					        	<option value="">请选择</option>
					        </select>
					      </div>
					      <div class="col-xs-3 hide">
					        <select class="form-control input_size child_domain">
					        	<option value="">请选择</option>
					        </select>
					      </div>
					      <div class="col-xs-3 no_padding_both">
					      	<button class="btn btn-primary" id="addDomain">添加</button>
					      </div>
					    </div>

					    <div class="form-group saveTechGroup">
					      <label class="col-xs-3 control-label no_padding_right">节能技术:</label>
					      <div class="col-xs-6">
					        <select class="form-control input_size save_tech">
					        	<option value="">请选择</option>
					        </select>
					      </div>
					      <div class="col-xs-3 no_padding_both">
					      	<button class="btn btn-primary" id="addTech">添加</button>
					      </div>
					    </div>

					    <div class="form-group saveDevice">
					      <label class="col-xs-3 control-label no_padding_right">使用的设备:</label>
					      <div class="col-xs-6">
					        <select class="form-control input_size save_device">
					        	<option value="">请选择</option>
					        </select>
					      </div>
					      <div class="col-xs-3 no_padding_both">
					      	<button class="btn btn-primary" id="addDevice">添加</button>
					      </div>
					    </div>

					    <div class="form-group saveUseTech">
					      <label class="col-xs-3 control-label no_padding_right">使用的技术:</label>
					      <div class="col-xs-6">
					        <select class="form-control input_size save_use_device">
					        	<option value="">请选择</option>
					        </select>
					      </div>
					      <div class="col-xs-3 no_padding_both">
					      	<button class="btn btn-primary" id="addTechnology">添加</button>
					      </div>
					    </div>

			    	    <div class="form-group">
			              <label for="saveRequire" class="col-xs-3 control-label no_padding_right">节能需求:</label>
			              <div class="col-xs-6">
			                <textarea class="form-control text_size" name="save_require" rows="3" id="saveRequire"></textarea>
			                <span class="help-block"></span>
			              </div>
			            </div>

				    	<div class="form-group">
				          <label for="textArea" class="col-xs-3 control-label no_padding_right">项目简介:</label>
				          <div class="col-xs-6">
				            <textarea class="form-control text_size" name="description" rows="3" id="textArea"></textarea>
				            <span class="help-block"></span>
				          </div>
				        </div>

					    <div class="form-group">
					      <label class="col-xs-3 control-label no_padding_right">项目主要内容:</label>
					      <div class="col-xs-9">
					      	<div id="container" style="height:500px;"></div>
					      </div>
					    </div>

					    <div class="form-group">
					      <div class="col-xs-12 text-center">
					        <button type="button" id="sub" class="btn btn-primary"> 提 交 </button>
					      </div>
					    </div>
				    </div>
				</div>
			</div>
		</div>
	</div>
	</div>
	<!-- 公共底部 -->
	@include("user.footer")
	@include("user.common")
</body>
<script type="text/html" id="mainbodyTemp">
<option value="">请选择</option>
{%each list as value}
<option value="{%value.id}">{%value.name}</option>
{%/each}
</script>

<script type="text/html" id="domainTemp">
<option value="">请选择</option>
{%each list as value}
<option value="{%value.id}">{%value.cate_name}</option>
{%/each}
</script>

<script type="text/html" id="deviceTemp">
<option value="">请选择</option>
{%each list as value}
<option value="{%value.id}">{%value.name}</option>
{%/each}
</script>

<script type="text/html" id="techTemp">
<option value="">请选择</option>
{%each list as value}
<option value="{%value.id}">{%value.tech_name}</option>
{%/each}
</script>

<script type="text/html" id="domainSelectTemp">
	<div class="form-group domainGroup">
	  <label class="col-xs-3 control-label no_padding_right"></label>
	  <div class="col-xs-3">
	    <select class="form-control input_size app_domain"></select>
	  </div>
	  <div class="col-xs-3 hide">
	    <select class="form-control input_size child_domain"></select>
	  </div>
	  <div class="col-xs-3 no_padding_both">
	  	<button class="btn btn-warning deleteTech">删除</button>
	  </div>
	</div>
</script>

<script type="text/html" id="saveTechTemp">
	<div class="form-group saveTechGroup">
      <label class="col-xs-3 control-label no_padding_right"></label>
      <div class="col-xs-6">
        <select class="form-control input_size save_tech"></select>
      </div>
      <div class="col-xs-3 no_padding_both">
      	<button class="btn btn-warning deleteTech">删除</button>
      </div>
    </div>
</script>

<script type="text/html" id="useDevice">
<div class="form-group saveDevice">
  <label class="col-xs-3 control-label no_padding_right"></label>
  <div class="col-xs-6">
    <select class="form-control input_size save_device"></select>
  </div>
  <div class="col-xs-3 no_padding_both">
  	<button class="btn btn-warning deleteUseDevice">删除</button>
  </div>
</div>
</script>

<script type="text/html" id="useTech">
<div class="form-group saveUseTech">
  <label class="col-xs-3 control-label no_padding_right"></label>
  <div class="col-xs-6">
    <select class="form-control input_size save_use_device"></select>
  </div>
  <div class="col-xs-3 no_padding_both">
  	<button class="btn btn-warning deleteUseTech">删除</button>
  </div>
</div>
</script>


<script type="text/javascript">
var que = "que";
$.getq(que, "<%url('uc/get_mainbody')%>", function (data){
	if(data.success){
		var html = template("mainbodyTemp", {list: data.data});
		$("#mbList").html(html);
	}
})
var ue = UE.getEditor('container');

$.getq(que, "<%url('uc/get_investment_type')%>", function (data){
	var str = '';
	$.each(data.data, function (k, v){
		str += '<option value="'+v.id+'">'+v.name+'</option>'
	})
	$("select[name='investment_type_id']").append(str);
})

$.getq(que, "<%url('uc/get_energy_type')%>", function (data){
	var str = '';
	$.each(data.data, function (k, v){
		str += '<option value="'+v.id+'">'+v.name+'</option>';
	})
	$("select[name='energy_type_id']").append(str);
})

$.getq(que, '<% url("uc/address/getarea") %>',function(data){
	var str = '';
	$.each(data.area,function(k, v){
		str += '<option value="'+v.area_id+'">'+v.area_name+'</option>';
	})
	$("#province").append(str);
})

$('#projectImg').AjaxFileUpload({
	path : "<% url('uc/user/upload') %>",
	onComplete : function(filename){
			$(this).siblings('input[class="hiddenName"]').val(filename.filename);
			$(this).parent(".file").siblings(".fileName").html(filename.filename);
		}
	});

$("#province").change(function(){
	var pid = $(this).val();
	$.getq(que, '<% url("uc/address/getarea") %>', {pid : pid}, function(data){
		var str = '<option value="-1">请选择</option>';
		$.each(data.area,function(k, v){
			str += '<option value="'+v.area_id+'">'+v.area_name+'</option>';
		})
		$("#city").html(str);
		$("#area").html('<option value="-1">请选择</option>');
	})
})

$("#city").change(function(){
	var pid = $(this).val();
	$.getq(que, '<% url("uc/address/getarea") %>', {pid : pid}, function(data){
		var str = '<option value="-1">请选择</option>';
		$.each(data.area,function(k, v){
			str += '<option value="'+v.area_id+'">'+v.area_name+'</option>';
		})
		$("#area").html(str);
	})
});

var appDomainSelect;
var dom;
$.getq(que, "<%url('uc/get_domains')%>", function(data){
	if(data.success){
		dom = data.data;
		var html = template("domainTemp", {list: dom});
		$(".app_domain").last().html(html);
		$(".app_domain").last().bind("change", function(){
			appDomainSelect = $(this);
			$.getq(que, "<%url('uc/get_domains')%>?parent_id=" + $(this).val(), function(data){
				if(data.success){
					var html = template("domainTemp", {list: data.data});
					appDomainSelect.parent().next().removeClass("hide");
					appDomainSelect.parent().next().find("select").html(html);
				}
			});
		});
	}
});

// 添加使用的设备


var dev;
$.getq(que, "<%url('uc/get_use_device')%>", function (data){
	if(data.success && data.data.length){
		dev = data.data;
		var html = template('deviceTemp', {list : dev});
		$(".save_device").last().html(html);
	}
})

$("#addDevice").bind("click", function(){
	var html = template("useDevice", {});
	$(html).insertAfter($(".saveDevice").last());
	var html = template('deviceTemp', {list : dev});
	$(".save_device").last().html(html);
	$(".deleteUseDevice").unbind("click");
	$(".deleteUseDevice").bind("click", function(){
		$(this).parents(".saveDevice").remove();
	})
})

//添加使用技术

var useTec;
$.getq(que, "<%url('uc/get_use_tech')%>", function (data){
	if(data.success && data.data.length){
		useTec = data.data;
		var html = template("techTemp", {list : useTec});
		$(".save_use_device").last().html(html);
	}
})

$("#addTechnology").bind("click", function(){
	var html = template("useTech", {});
	$(html).insertAfter($(".saveUseTech").last());
	var html = template("techTemp", {list : useTec});
	$(".save_use_device").last().html(html);
	$(".deleteUseTech").unbind("click");
	$(".deleteUseTech").bind("click", function(){
		$(this).parents(".saveUseTech").remove();
	})
})

$("#addDomain").bind("click", function(){
	var html = template("domainSelectTemp", {});
	$(html).insertAfter($(".domainGroup").last());
	$(".deleteTech").unbind("click");
	$(".deleteTech").bind("click", function(){
		$(this).parents(".domainGroup").remove();
	})
	var html = template("domainTemp", {list: dom});
	$(".app_domain").last().html(html);
	$(".app_domain").last().bind("change", function(){
		appDomainSelect = $(this);
		$.getq(que,"<%url('uc/get_domains')%>?parent_id=" + $(this).val(), function(data){
			if(data.success && data.data.length){
				var html = template("domainTemp", {list: data.data});
				appDomainSelect.parent().next().removeClass("hide");
				appDomainSelect.parent().next().find("select").html(html);
			}
		});
	});
});

var tec;
$.getq(que,"<%url('uc/get_techs')%>", function(data){
	if(data.success && data.data.length){
		tec = data.data;
		var html = template("domainTemp", {list: tec});
		$(".save_tech").last().html(html);
	}
});

$("#addTech").bind("click", function(){
	var html = template("saveTechTemp", {});
	$(html).insertAfter($(".saveTechGroup").last());

	var html = template("domainTemp", {list: tec});
	$(".save_tech").last().html(html);
	$(".deleteTech").unbind("click");
	$(".deleteTech").bind("click", function(){
		$(this).parents(".saveTechGroup").remove();
	})
});



$("#sub").click(function(){

	var name = $("input[name='name']").val().trim();
	var investment_scale = $("input[name='investment_scale']").val().trim();
	var investment_type_id = $("select[name='investment_type_id']").val().trim();
	var efficiency = $("input[name='efficiency']").val().trim();
	var start_time = $("input[name='start_time']").val().trim();
	var end_time = $("input[name='end_time']").val().trim();
	var province = $("select[name='province']").val().trim();
	var city = $("select[name='city']").val().trim();
	var area = $("select[name='area']").val().trim();
	var address = $("input[name='address']").val().trim();
	var is_request_award = $("input[name='is_request_award']:checked").val().trim();
	var is_request_subsidy = $("input[name='is_request_subsidy']:checked").val().trim();
	var is_request_rebate = $("input[name='is_request_rebate']:checked").val().trim();
	var image = $("input[name='image']").val().trim();
	var description = $("textarea[name='description']").val().trim();
	var save_require = $("textarea[name='save_require']").val().trim();
	var content = encodeURIComponent(ue.getContent());
	var mainBody = $("#mbList").val();


	if (name == '' || investment_scale == '' || investment_type_id == '' || efficiency == '' || start_time == '' || end_time == '' || province < 1  || city < 1  || address == '' || is_request_award == '' || is_request_subsidy == '' || is_request_rebate == '' || description == '' || content == '' || mainBody == '' || save_require == '')
	{
		warning('','必填信息不能为空');
		return false;
	}
	if(textNum(save_require) >=20){
		warning("", "节能需求只能输入20个字符");
		return ;
	}

	var domains = [];
	$.each($(".app_domain"), function(index, item){
		if($(item).parent().next().hasClass("hide")){
			domains.push($(item).val());
		}else{
			domains.push($(item).parent().next().find("select").val());
		}
	});

	var bool = false;
	$.each(domains, function(index, item){
		if(item == ""){
			warning("", "请选择应用领域！");
			bool = true;
			return true;
		}
	});

	if(bool){
		return;
	}

	var techs = [];
	$.each($(".save_tech"), function(index, item){
		if($(item).val()){
			techs.push($(item).val());
		}
	});
	if(techs.length == 0){
		warning("", "请选节能技术");
		return;
	}

	var device = [];
	$.each($(".save_device"), function (index, item){
		if($(item).val()){
			device.push($(item).val());
		}
	})
	if(device.length == 0){
		warning("", "请选择使用的设备");
		return;
	}

	var useTech = [];
	$.each($(".save_use_device"), function (index, item){
		if($(item).val()){
			useTech.push($(item).val());
		}
	})
	if(useTech.length == 0){
		warning("", "请选择使用的技术");
		return;
	}
	$.post("add_project/add", {
		name : name,
		investment_scale : investment_scale,
		investment_type_id : investment_type_id,
		efficiency : efficiency,
		end_time : end_time,
		province : province,
		city : city,
		area : area,
		address : address,
		is_request_award : is_request_award,
		is_request_subsidy : is_request_subsidy,
		is_request_rebate : is_request_rebate,
		image : image,
		description : description,
		content : content,
		domains: domains,
		techs: techs,
		main_body: mainBody,
		save_require: save_require,
		start_time: start_time,
		device : device,
		useTech : useTech
	},function (data){
		if(data.success){
			success("", "提交成功");
			setTimeout(function(){
				window.location.href="project";
			},1000)
		}
	})
})

</script>
</html>